package com.pf.controller;

import com.pf.dto.BaseResult;
import com.pf.enums.BaseResultEnum;
import com.pf.exception.RetryException;
import com.pf.utils.BaseResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2021/8/10
 */
@Slf4j
@RestController
@RequestMapping("/task")
public class TaskController {

    /**
     * 模拟任务执行成功
     *
     * @return
     */
    @GetMapping("/job1")
    public BaseResult job1() {
        log.info(">>>>> TaskController job1 execute success.... ");
        return BaseResultUtils.success();
    }

    /**
     * 模拟任务执行失败，需重试
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/job2")
    public BaseResult job2() throws Exception {
        if (true) {
            log.info(">>>>> TaskController job2 execute error.... ");
            throw new RetryException(BaseResultEnum.RETRY);
        }
        log.info(">>>>> TaskController job2 execute success.... ");
        return BaseResultUtils.success();
    }
}
